﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DungeonCrawl
{
    class DungeonCrawl
    {
        private char[,] dungeon = new char[10, 10];
        int playerx, playery;

        public DungeonCrawl()
        {
            Random rnd = new Random();

            for (int i = 0; i < dungeon.GetLength(0); i++)
            {
                for (int j = 0; j < dungeon.GetLength(1); j++)
                {
                    dungeon[i, j] = '.';
                }
            }

            //place player
            playerx = rnd.Next() % 10;
            playery = rnd.Next() % 10;
            dungeon[playerx, playery] = 'P';

            //place treasure
            int tempx, tempy;
            do
            {
                tempx = rnd.Next() % 10;
                tempy = rnd.Next() % 10;
            } while ((tempx = rnd.Next() % 10) == playerx && (tempy = rnd.Next() % 10) == playery);
            dungeon[tempx, tempy] = 'X';

            //place traps
            for (int i = 0; i < rnd.Next() % 4 + 3; i++)
            {
                do{
                    tempx = rnd.Next() % 10;
                    tempy = rnd.Next() % 10;
                } while (dungeon[tempx, tempy] == 'P' || dungeon[tempx, tempy] == 'X' || dungeon[tempx, tempy] == 'T');
                dungeon[tempx, tempy] = 'T';
            }
        }

        public void game()
        {
            ConsoleKeyInfo key = Console.ReadKey();
            switch (key.Key)
            {
                case ConsoleKey.LeftArrow:
                    if (playerx > 0)
                        playerx--;
                    break;
                case ConsoleKey.RightArrow:
                    if (playerx < dungeon.GetLength(0))
                        playerx++;
                    break;
                case ConsoleKey.UpArrow:
                    if (playery > 0)
                        playery--;
                    break;
                case ConsoleKey.DownArrow:
                    if (playery < dungeon.GetLength(1))
                        playery++;
                    break;
                default:
                    break;
            }
            draw();
        }

        private void draw()
        {
            for (int i = 0; i < dungeon.GetLength(0); i++)
            {
                for (int j = 0; j < dungeon.GetLength(1); j++)
                {
                    Console.Write(dungeon[i, j]);
                }
                Console.Write('\n');
            }
        }

    }
}
